<template>
	<view class="detail-section">
		<view class="show-picture">
			<image src="../../static/notFound.png"></image>
		</view>
		<view class="detail">
			<view class="card">
				<view>
					<span class="price">￥{{profile.price}}/月</span>
					<span class="time">{{profile.releaseTime}} 发布</span>
				</view>
				<view class="name">
					<h3>{{profile.houseName}}</h3>
				</view>
			</view>
			<view class="card">
				<view>
					<span class="text">地址</span>{{profile.address}}
				</view>
				<view>
					<view class="text">详细</view>{{profile.detailedAddress}}
				</view>
			</view>
			<view class="card">
				<view class="text">描述</view>{{profile.description}}
			</view>

			<button type="primary" @click="reserve">预定</button>
		</view>
	</view>

	</view>
</template>
<script>
	import moment from '@/common/moment';
	import listCell from '@/components/oa-list-cell';
	import {
		mapMutations
	} from 'vuex';

	export default {
		components: {
			listCell
		},
		data() {
			return {
				hasLogin: this.$mRed.isLogin(),
				profile: {}
			};
		},
		async onShow() {
			// 初始化数据
			await this.initData();
		},

		onLoad(option) {
			if (option['id'] != undefined) {
				this.$mRed.request({
					url: 'api/house/public/detail/' + option['id'],
					method: 'GET',
				}).then(r => {
					let result = r[1].data
					if (result.code == 200) {
						this.profile = result.data
						this.profile.releaseTime = moment(this.profile.releaseTime).format("YYYY-MM-DD")
						this.profile.picture = this.handlerPicture(this.profile.picture)
					} else {
						this.$mHelper.toast('出现意外错误')
					}
				})
			}

			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.themeColor.color,
				animation: {
					duration: 400,
					timingFunc: 'easeIn'
				}
			})
		},

		methods: {
			// 数据初始化
			async initData() {},
			// 统一跳转接口,拦截未登录路由
			navTo(route) {
				this.$mRouter.push({
					route
				});
			},
			handlerPicture(pictureUrl) {
				return pictureUrl != undefined ?
					this.$mRed.baseURL + pictureUrl :
					'../../static/notFound.png'
			},
			reserve() {
				if (!this.$mRed.isLogin()) {
					uni.showModal({
						title: '提示',
						content: '登录后才能预定',
						confirmText: '登录',
						success: r => {
							if (r.confirm) {
								this.navTo('/pages/public/login')
							}
						}
					})
				} else {
					this.$mHelper.toast('预定中...')
					this.$mRed.request({
						url: 'api/fight/' + this.profile.houseId,
						method: 'POST',
					}).then(r => {
						let result = r[1].data

						if (result.code == 200) {
							uni.showModal({
								title: '消息',
								content: '预定成功，去支付？',
								success: r => {
									if (r.confirm) {
										this.navTo('/pages/user/orders')
									}
								}
							})
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}


						console.log(r[1].data)

					})
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background-color: $page-color-base;
	}

	.detail-section {
		.show-picture {
			// border: 1px solid black;
			width: 100%;
			height: 500upx;
			overflow: hidden;

			image {
				width: 100%;
			}
		}

		.detail {
			padding: 0 30upx 20upx;

			.card {
				margin-top: $spacing-lg;
				padding: 20px 10px;
				background-color: white;
				border-radius: 10upx;
			}

			button {
				margin-top: $spacing-lg;
			}

			.price {
				color: red;
				font-size: $font-lg
			}

			.time {
				color: grey;
				float: right;
				font-size: $font-sm;
			}

			.name {
				font-weight: bold;
			}

			.text {
				display: block;
				color: grey;
				width: 15%;
				float: left;
				// font-size: $font-sm;
			}
		}
	}
</style>
